/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sasp_messages;

import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.JSONException;
import org.json.JSONObject;

/**
 *
 * @author mauriello
 */
public class SASPReply {
    public final static String ACK   = "ACK";

    private String type;
    private int originatorID;
    private int destinationID;
    private int replyToID;
    private Date dateTime;
    private JSONObject replyBody;
    private JSONObject theMessage;

    public void setDateTime( ) {
        dateTime = new Date( );
    }

    public Date getDateTime( ) {
        return dateTime;
    }

    public void setType( String _t ) {
        type = _t;
    }

    public String getType( ) {
        return type;
    }

    public void setReplyBody( JSONObject _r ) {
        replyBody = _r;
    }

    public JSONObject getReplyBody( ) {
        return replyBody;
    }

    public void setOriginatorID( int _o ) {
        originatorID = _o;
    }

    public int getOriginatorID( ) {
        return originatorID;
    }

    public void setReplyToID( int _r ) {
        replyToID = _r;
    }

    public int getReplyToID( ) {
        return replyToID;
    }

    public void setDestinationID( int _d ) {
        destinationID = _d;
    }

    public int getDestinationID( ) {
        return destinationID;
    }

    public SASPReply( ) {
        theMessage = new JSONObject();
        replyBody = new JSONObject();
        dateTime = new Date();
    }

    public SASPReply(int _o, int _d, int _r ) {
        this();
        originatorID = _o;
        destinationID = _d;
        replyToID = _r;
    }

    public SASPReply( String _inJson ) {
        try {
            theMessage = new JSONObject(_inJson);
            replyBody = theMessage.getJSONObject("ReplyBody");
            originatorID = theMessage.getInt("OriginatorID");
            destinationID = theMessage.getInt("DestinationID");
            replyToID = theMessage.getInt("ReplyToID");
            /* TODO: Parse Date/Time */
        } catch (JSONException ex) {
            Logger.getLogger(SASPCommand.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /* Override ToString Method in Concrete Command Classes */
}
